use super::handlers::*;

use actix_web::{get, web, HttpResponse, Responder};

// curl 127.0.0.1:8080/
#[get("/")]
pub async fn hello_router() -> impl Responder {
  HttpResponse::Ok().body("Hello world!")
}

pub fn general_routes(cfg: &mut web::ServiceConfig) {
  // curl 127.0.0.1:8080/health
  cfg.route("/health", web::get().to(health_check_handler));
}

pub fn course_routes(cfg: &mut web::ServiceConfig) {
  cfg.service(
    web::scope("/courses")
      // curl -X POST http://127.0.0.1:8080/courses/ -H "Content-Type: application/json" -d '{"teacher_id": 1, "name": "First course"}'
      .route("/", web::post().to(new_course))
      // curl http://127.0.0.1:8080/courses/1
      .route("/{teacher_id}", web::get().to(get_courses_for_teacher))
      // curl http://127.0.0.1:8080/courses/1/2
      .route(
        "/{teacher_id}/{course_id}",
        web::get().to(get_course_detail),
      ),
  );
}
